<?
include_once("test.php");

function waitKeyQ() {
	$ended=0;
	while ($ended==0) {
		while (SDL_PollEvent(&$event)) {
			switch($event["type"]) {					
			case SDL_QUIT:
				echo "SDL_Quit received, quitting\n";
				$ended=1;
				break;
			case SDL_KEYDOWN:
				$keysym=$event["key"]["keysym"]["sym"];
				if ($keysym==SDLK_q) {
					echo "Q pressed, quitting\n";
					$ended=1;
				}
				break;
			}
		}
	}

}
function thread_1_test($params) {
	echo "Thread_1_test called\n";	
	var_dump($params);
	return 1000;
}
class thread1obj {
	function thread1tst($params) {
		echo "Thread_1_test called\n";	
		var_dump($params);
		return 1000;
	}

}
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN')
	dl('php_sdl.dll');
else 
	dl('sdl.so');
class test_e001 extends test{
	function do_test($idx) {
		switch($idx) {
		case 1:
			echo "Starting\n";
			echo "Pressing Q to exit\n";
			SDL_Init(SDL_INIT_VIDEO);
			$flags=SDL_SWSURFACE;
			$screen=SDL_SetVideoMode(640, 480, 32, $flags);
			$ended=0;
			while ($ended==0) {
				while (SDL_WaitEvent(&$event)) {
					switch($event["type"]) {
					case SDL_QUIT:
					    printf("Quit requested, quitting.\n");					
						$ended=1;
						die("");
						break;
					case SDL_KEYDOWN:
						$keysym=$event["key"]["keysym"]["sym"];
						if ($keysym==SDLK_q) {
							echo "Q pressed, quitting\n";
							$ended=1;
						}
						break;
					}
					echo "*";
				}

			}
			$ret=SDL_Quit();			
			echo "Quitting\n";
			break;						

		case 2:
			echo "Starting\n";
			echo "Pressing Q to exit\n";
			SDL_Init(SDL_INIT_VIDEO);
			$flags=SDL_SWSURFACE;
			$screen=SDL_SetVideoMode(640, 480, 32, $flags);
			$ended=0;
			while ($ended==0) {
				while (SDL_PollEvent(&$event)) {
					switch($event["type"]) {
					case SDL_QUIT:
					    printf("Quit requested, quitting.\n");					
						$ended=1;
						break;
					case SDL_KEYDOWN:
						$keysym=$event["key"]["keysym"]["sym"];
						if ($keysym==SDLK_q) {
							echo "Q pressed, quitting\n";
							$ended=1;
						}
						break;						
					}
					echo "*";
				}
			}
			$ret=SDL_Quit();
			
			var_dump($ret);
			break;	
		case 3:
			SDL_Init(SDL_INIT_VIDEO+SDL_INIT_TIMER);
			$flags=SDL_SWSURFACE;
			$screen=SDL_SetVideoMode(640, 480, 32, $flags);
			
			$ret=sdl_addtimer(1000,"thread_1_test",array("prova"=>100,"dato2"=>"500"));
			print_r($ret);
			echo "\n";
			echo "Done add timer\n";
			waitKeyQ();
			
			echo "Done";
			sdl_removetimer($ret);
			SDL_Quit();
			break;			
		case 4:
			SDL_Init(SDL_INIT_VIDEO+SDL_INIT_TIMER);
			$flags=SDL_SWSURFACE;
			$screen=SDL_SetVideoMode(640, 480, 32, $flags);
			$o=new thread1obj();
			
			$ret=sdl_addtimer(1000,array(&$o,"thread1tst"),array("prova"=>100,"dato2"=>"500"));
			print_r($ret);
			echo "\n";
			echo "Done add timer\n";
			waitKeyQ();
			
			echo "Done";
			sdl_removetimer($ret);
			SDL_Quit();
			break;			
		}
	}
	function get_test_list() {
		return array(
			1=>"sdl_waitevent test",
			2=>"sdl_pollevent test",
			3=>"sdl_addtimer and sdl_removetimer test",	
			4=>"sdl_addtimer and sdl_removetimer test with object",	
		);
	}
}
?>
